export interface IVFocusBinding {
  value: boolean | (() => boolean) | (() => Promise<boolean>);
}

export const vFocus = {
  async mounted(el: HTMLElement, { value }: IVFocusBinding) {
    if (typeof value === "function") {
      const result = await value();
      Boolean(result) && el.focus();
    }

    if (typeof value === "undefined") {
      el.focus();
      return;
    }
    Boolean(value) && el.focus();
  },
};
